﻿@model iHouse.Web.Infrastructure.BookFormView
@{
    ViewBag.Title = Resources.EditBookTitle;
    Layout = "~/Views/Shared/_Root.cshtml";
}

<div class="logon-container">
    @using (Ajax.BeginForm(new AjaxOptions() { OnSuccess = "onFormSuccess", OnComplete = "onFormCompleted" }))
    {
        @Html.ValidationSummary(true)
        @Html.HiddenFor(model => model.Book.ID, new { id = "bookID" })
        <div class="revright">
            <span class="ratehead">@Resources.BookRateHeader</span>
            <div class="rateitem">
                <div class="rateit">
                    @Html.HiddenFor(model => model.Book.Score, new { id = "score", value = this.Model.Book.Score.GetValueOrDefault() })
                </div>
            </div>
        </div>
        <div class="clear">
        </div>
        <p>
            @Html.LabelFor(model => model.Book.Name, Resources.BookName)
            @Html.EditorFor(model => model.Book.Name)
            @Html.ValidationMessageFor(model => model.Book.Name)
        </p>
            
        <p>
            @Html.LabelFor(model => model.Book.Author, Resources.BookAuthor)
            @Html.EditorFor(model => model.Book.Author)
            @Html.ValidationMessageFor(model => model.Book.Author)
        </p>
           
            
        <p>
            @Html.LabelFor(model => model.Book.PublishDate, Resources.BookPublisherDate)
            @Html.TextBoxFor(model => model.Book.PublishDate, new { @class = "date-field", id = "publishDate" })
            @Html.ValidationMessageFor(model => model.Book.PublishDate)
        </p>
            
        <p>
            @Html.LabelFor(model => model.Book.CategoryID, Resources.BookCategory)
            @Html.DropDownListFor(model => model.Book.CategoryID, Model.Categories)
            @Html.ValidationMessageFor(model => model.Book.CategoryID)
        </p>
           
        <p>
            @Html.LabelFor(model => model.Book.PublisherID, Resources.BookPublisher)
            @Html.DropDownListFor(model => model.Book.PublisherID, Model.Publishers)
            @Html.ValidationMessageFor(model => model.Book.PublisherID)
        </p>
            
        <p>
            @Html.LabelFor(model => model.Book.Language, Resources.BookLanguage)
            @Html.DropDownListFor(model => model.Book.Language, Model.Languages)
            @Html.ValidationMessageFor(model => model.Book.Language)
        </p>
            
        <p>
            @Html.LabelFor(model => model.Book.Type, Resources.BookType)
            @Html.DropDownListFor(x => x.Book.Type, Model.BookTypes)
        </p> 
           
        <p>
            @Html.LabelFor(model => model.Book.ISBN10)
            @Html.EditorFor(model => model.Book.ISBN10)
            @Html.ValidationMessageFor(model => model.Book.ISBN10)
        </p>
            
        <p>
            @Html.LabelFor(model => model.Book.ISBN13)
            @Html.EditorFor(model => model.Book.ISBN13)
            @Html.ValidationMessageFor(model => model.Book.ISBN13)
        </p>
            
        <p class="clearfix">
            <input type="submit" id="entitySubmit" value="@Resources.Submit" />
        </p>
    }
</div>

<div class="clear">
</div>
<script type="text/javascript">
    function InitDatePicker() {
        var date;

        if ('@Convert.ToString(this.ViewContext.RouteData.Values["action"])' == "Edit" && '@Model.Book.PublishDate.HasValue' == "True") {
            date = '@Model.Book.PublishDate.GetValueOrDefault().ToShortDateString()';
        }
        else {
            date = '';
        }

        $("#publishDate").datepicker(
        {
            showOn: 'button',
            buttonImage: Sys.loader.applicationPath + "Content/images/Calendar.png",
            buttonImageOnly: true
        }).attr('value', date);
    };

    Sys.require(["BookUI", "jqUI"], InitDatePicker);
    Sys.require(["jquery.validate.unobtrusive", "MicrosoftMvcAjax", "jquery.unobtrusive-ajax"]);

    if ('@System.Threading.Thread.CurrentThread.CurrentUICulture.Name' == "zh-CN") {
        Sys.require(["jqUI.Datepicker.Culture.cn"]);
    }

    Sys.require(["BookUI", "rateit"], function () { InitRateit(false); });

    function onFormSuccess() {
        window.parent.$.fn.colorbox.close();
    }

    function onFormCompleted(result) {
        window.parent.$('#bookShelf').html(result.responseText);
    }
</script>
